package com.taskcollection.service;

import com.taskcollection.bean.StudentBean;
import com.taskcollection.bean.StudentProjectBean;
import com.taskcollection.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by haocongshun on 2016/7/30.
 */
public class StudentProjectService {
    public List<StudentBean> getByProjectTeamId(String ProjectTeam_id){
        String sql = "select Student_id from studentproject where ProjectTeam_id=?";
        Connection conn = DBConnection.getinstance().getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<StudentBean> studentList = new ArrayList<StudentBean>();
        try{
            ps = conn.prepareStatement(sql);
            ps.setString(1,ProjectTeam_id);
            rs = ps.executeQuery();
            while (rs.next()){
                StudentProjectBean spb = new StudentProjectBean();
                spb.setStudent_id(rs.getString("Student_id"));
                StudentService ss = new StudentService();
                spb.setStudent(ss.getById(spb.getStudent_id()));
                studentList.add(spb.getStudent());
            }
            return studentList;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
